package com.biboheart.adapter.express.support;

import com.biboheart.adapter.express.operation.OperatorRegistry;
import com.biboheart.adapter.express.operation.OperatorService;
import com.biboheart.adapter.support.enums.OperatorEnum;

public class DefaultOperationService extends GenericOperationService{
    private static volatile DefaultOperationService sharedInstance;

    public DefaultOperationService() {addOperator(this);}

    public static OperatorService getSharedInstance() {
        DefaultOperationService as = sharedInstance;
        if (null == as) {
            synchronized (DefaultOperationService.class) {
                as = sharedInstance;
                if (as == null) {
                    as = new DefaultOperationService();
                    sharedInstance = as;
                }
            }
        }
        return as;
    }

    public static void addOperator(OperatorRegistry operatorRegistry) {
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_ADD.code(), new AdditionCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_SUB.code(), new SubtractCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_MUL.code(), new MultiplyCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_DIV.code(), new DivisionCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_REM.code(), new RemainderCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_BIT_AND.code(), new BitAndCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_BIT_OR.code(), new BitOrCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_BIT_XOR.code(), new BitXorCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_BIT_INV.code(), new BitInvCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_BIT_LEFT.code(), new BitLeftCalculate());
        operatorRegistry.addOperator(OperatorEnum.OPERATOR_BIT_RIGHT.code(), new BitRightCalculate());
    }
}
